package com.reny.ll.git.core

import android.os.SystemClock

class ClickUtils {

    companion object{

        private val records: MutableMap<String, Long> = HashMap()

        @JvmStatic
        fun isFastClick(): Boolean {
            if (records.size > 1000) {
                records.clear()
            }

            //本方法被调用的文件名和行号作为标记
            val ste = Throwable().stackTrace[1]
            val key = ste.fileName + ste.lineNumber
            var lastClickTime = records[key]
            val thisClickTime = SystemClock.elapsedRealtime()
            records[key] = thisClickTime
            if (lastClickTime == null) {
                lastClickTime = 0L
            }
            val timeDuration = thisClickTime - lastClickTime
            return timeDuration in 1..499
        }


        private val clickMap = HashMap<Any, Long>(5)

        @JvmStatic
        fun isDoubleClick(key:Any) : Boolean{
            if(!clickMap.containsKey(key)){
                clickMap[key] = 0
            }

            val time = SystemClock.elapsedRealtime()
            if (time - clickMap[key]!! < 500) {
                return true
            }
            clickMap[key] = time
            return false
        }



    }

}